package com.vitogiovanni.tobook;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.vitogiovanni.tobook.utilities.NetworkChecker;
import com.vitogiovanni.tobook.utilities.UserEmailFetcher;

public class MainActivity extends Activity {

	public static final String EMAIL_UTENTE = "com.vitogiovanni.tobook.EMAIL_UTENTE";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		getActionBar().hide();
	}
	
	/**
	 * Called when user clicks on button button_qui_vicino
	 */
	public void quiVicino(View view)
	{
		if (!NetworkChecker.isInternetAvailable(MainActivity.this)) {
			NetworkChecker.noConnectionToast(MainActivity.this);
		} else {
		Intent intent = new Intent(MainActivity.this, ListaLocaliActivity.class);
		startActivity(intent);
		}
	}
	
	
	/** Called when user clicks on button button_ricerca_locali */
	public void ricercaLocali(View view) {
		if (!NetworkChecker.isInternetAvailable(MainActivity.this)) {
			NetworkChecker.noConnectionToast(MainActivity.this);
		} else {
			Intent intent = new Intent(this, RicercaLocaliActivity.class);
			startActivity(intent);
		}
	}

	public void localiPreferiti(View view) {
		if (!NetworkChecker.isInternetAvailable(MainActivity.this)) {
			NetworkChecker.noConnectionToast(MainActivity.this);
		} else {
		Context context = getApplicationContext();
		
		CharSequence text = UserEmailFetcher.getEmail(context);
		Intent intent = new Intent(this, PreferitiActivity.class);
		intent.putExtra(EMAIL_UTENTE, text.toString());
		startActivity(intent);
		}
	}
	
	public void listaPrenotazioni(View view)
	{
		if (!NetworkChecker.isInternetAvailable(MainActivity.this)) {
			NetworkChecker.noConnectionToast(MainActivity.this);
		} else {
		Context context = getApplicationContext();
		
		CharSequence text = UserEmailFetcher.getEmail(context);
		Intent intent = new Intent(this, ListaPrenotazioniActivity.class);
		intent.putExtra(EMAIL_UTENTE, text.toString());
		startActivity(intent);
		}
	}
	
	/*@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}*/
}